<template>
	<view>
		<view style="color: #fff;padding: 30rpx;font-size: 50rpx;font-weight: bold;letter-spacing: 20rpx;">渠道申请</view>
		<view class="mode">
			<u-form :model="form" ref="uForm">
				<u-form-item label="姓名" prop="realname">
					<u-input v-model="form.realname" placeholder="请输入姓名" />
				</u-form-item>
				<u-form-item label="电话" prop="phone">
					<u-input v-model="form.phone" placeholder="请输入电话" maxlength="11"/>
				</u-form-item>
				<u-form-item label="申请说明" prop="remark" label-position="top">
					<u-input v-model="form.remark" placeholder="请输入申请说明" />
				</u-form-item>
			</u-form>
			<view style="position: absolute;bottom: 20rpx;width: 80%;left:10% ;">
				<u-button @click="submit" :custom-style="{background:'#4066F4',color:'#fff'}" shape="circle">提交</u-button>
			</view>
			
		</view>
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					realname: '',
					remark: '',
					phone:""
				},
				rules: {
					realname: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
					remark: [{
						min: 5,
						message: '申请说明不能少于5个字',
						trigger: 'change'
					}],
					phone: [{
						
						message: '手机号码不正确',
						trigger: 'change'
					}, {
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
						
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// this.$u.test.mobile()就是返回true或者false的
							return this.$u.test.mobile(value);
						},
						message: '手机号码不正确',
						// 触发器可以同时用blur和change
						trigger: ['change', 'blur'],
					}],
					
				}
			};
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$u.post('/user/apply', this.form).then(res => {
							
							this.$refs.uToast.show({
								title: '申请成功',
								type: 'success',
								back:true
							})
						}).catch(err => {})
					} else {
						
					}
				});
			}
		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	};
</script>


<style>
	page{
		background: #4066F4;
		height: 100vh;
	}
	.mode{
		height: 80vh;
		margin-top: 20rpx;
		position: relative;
	}
</style>
